package com.ruoyi.web.controller.integral;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.integral.domain.IntegralApproval;
import com.ruoyi.integral.service.IIntegralApprovalService;
import com.ruoyi.web.core.base.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 审批管理 信息操作处理
 * 
 * @author sunli
 * @date 2018-10-24
 */
@Controller
@RequestMapping("/integral/integralApproval")
public class IntegralApprovalController extends BaseController
{
    private String prefix = "integral/integralApproval";
	
	@Autowired
	private IIntegralApprovalService integralApprovalService;
	
	@RequiresPermissions("integral:integralApproval:view")
	@GetMapping()
	public String integralApproval()
	{
	    return prefix + "/integralApproval";
	}
	
	/**
	 * 查询审批管理列表
	 */
	@RequiresPermissions("integral:integralApproval:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(IntegralApproval integralApproval)
	{
		startPage();
        List<IntegralApproval> list = integralApprovalService.selectIntegralApprovalList(integralApproval);
        return getDataTable(list);
	}
	
	/**
	 * 新增审批管理
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存审批管理
	 */
	@RequiresPermissions("integral:integralApproval:add")
	@Log(title = "审批管理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(IntegralApproval integralApproval)
	{		
		return toAjax(integralApprovalService.insertIntegralApproval(integralApproval));
	}

	/**
	 * 修改审批管理
	 */
	@GetMapping("/edit/{approvalId}")
	public String edit(@PathVariable("approvalId") Integer approvalId, ModelMap mmap)
	{
		IntegralApproval integralApproval = integralApprovalService.selectIntegralApprovalById(approvalId);
		mmap.put("integralApproval", integralApproval);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存审批管理
	 */
	@RequiresPermissions("integral:integralApproval:edit")
	@Log(title = "审批管理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(IntegralApproval integralApproval)
	{		
		return toAjax(integralApprovalService.updateIntegralApproval(integralApproval));
	}
	
	/**
	 * 删除审批管理
	 */
	@RequiresPermissions("integral:integralApproval:remove")
	@Log(title = "审批管理", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(integralApprovalService.deleteIntegralApprovalByIds(ids));
	}

	/**
	 * 修改审批转态 添加用户积分
	 */
	@RequiresPermissions("integral:integralApproval:success")
	@Log(title = "审批管理", businessType = BusinessType.OTHER)
	@GetMapping("/success/{approvalId}/{status}")
	@ResponseBody
	public AjaxResult successStatus(@PathVariable("approvalId") String approvalId,@PathVariable("status") String status)
	{
		return toAjax(integralApprovalService.successStatus( Integer.parseInt(approvalId),Integer.parseInt(status)));
	}
}
